

import json,random,time
import hashlib
#用于读取项目目录下的yaml_name.db
import yaml  ,os,sys  ,json                             #第三方模块yaml          需要下载  是一个配置文件解析的第三方模块
project_dir_path=os.path.dirname(os.path.dirname(os.path.abspath(__file__)))  #项目路径
sys.path.append(project_dir_path)           #将项目路径添加到环境中   使得python可以导包
def get_file_paths(directory):  
    file_paths = []  
    for root, dirs, files in os.walk(directory):  
        for file in files:  
            file_path = os.path.join(root, file)  
            file_paths.append(file_path)  # 将完整路径和文件名保存到列表中  
    return file_paths  

def get_folder_paths(directory):  
    folder_paths = []  
    for root, dirs, files in os.walk(directory):  
        if not dirs and directory!=root:  # 如果当前目录没有子目录  
            folder_paths.append(root)  # 将当前目录的完整路径添加到列表中  
    return folder_paths 

def get_folder_paths2(directory):  
    folder_paths = []  
    for root, dirs, files in os.walk(directory):  
        if 'main.js'in files:
            folder_paths.append(root)  # 将当前目录的完整路径添加到列表中  
    return folder_paths  
def my_js(dir_path,static_path):
    str_js=''
    file_lst=get_file_paths(dir_path)
    lst_dir=sorted(file_lst,key=lambda item:int(os.path.basename(item).split('_')[0]) )
    for path in lst_dir:
        try:
            with open(path,'r',encoding='utf-8')as f:
                str_js=str_js+'\n'+f.read()
        except Exception as e:print(e)
    with open(static_path+os.sep+'base.js','w',encoding='utf-8')as f:
        f.write(str_js)
def base_vue_template(dir_path,static_path):
    str_js=''
    str_css=''
    file_lst=get_folder_paths2(dir_path)
    lstdir=sorted(file_lst,key=lambda item:int(os.path.basename(item).split('_')[0]) )
    for new_dir_path in lstdir:
        try:
            with open(new_dir_path+os.sep+'main.js','r',encoding='utf-8')as f:
                str_js=str_js+'\n'+f.read()
        except Exception as e:pass
        try:
            with open(new_dir_path+os.sep+'main.css','r',encoding='utf-8')as f:
                str_css=str_css+'\n'+f.read()
        except Exception as e:pass
    with open(static_path+os.sep+'base_vue_template.js','w',encoding='utf-8')as f:
        f.write(str_js)
    with open(static_path+os.sep+'base_vue_template.css','w',encoding='utf-8')as f:
        f.write(str_css)
if __name__=="__main__":
    dir_path=project_dir_path+os.sep+'web'+os.sep+'web_js'
    my_js(dir_path,project_dir_path+os.sep+'other'+os.sep+'test')

    dir_path=project_dir_path+os.sep+'web'+os.sep+'web_vue_template'
    base_vue_template(dir_path,project_dir_path+os.sep+'other'+os.sep+'test')